﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using Gizmox.WebGUI.Forms;
using Agresso.Interface.Layer.Domain;

namespace Agresso.Interface.Layer.Web
{
    public class UserControlFactory
    {
        Hashtable m_userControlCollection = new Hashtable();
        public const string ADMIN = "Administrator";
        public const string USER = "User";
        public const string USER_ROLE = "User Role";
        public const string CONFIGURATION = "Configuration";
        public const string SCHEDULE_TASK = "Schedule Task";
        public const string SOFTMAR = "Softmar";
        public const string SOFTMAR_TCRELET = "Softmar TC Relet";
        public const string SOFTMAR_VESSEL = "Softmar Vessel Master";
        public const string SOFTMAR_VOYAGECARGORELET = "Softmar Voyage and Cargo Relet";
        public const string SOFTMAR_PROFORMA_INVOICE = "Softmar Proforma Invoice";
        public const string SOFTMAR_FREIGHTHIREINVOICE = "Softmar Freight Hire Invoice";
        public const string SOFTMAR_STATEMENT = "Softmar Statement Invoice";
        public const string SOFTMAR_VESSEL_MAPPING = "Softmar Agresso Vessel Mapping";
        public const string ADMIN_MAPPING_MASTER = "Mapping Master";
        public const string SOFTMAR_PROFITCENTRE_MAPPING = "Softmar Agresso ProfitCentre Mapping";
        public const string SOFTMAR_SUPPLIER_CUSTOMER_MAPPING = "Softmar Agresso Company Table Mapping";
        public const string SOFTMAR_CHARGE_TYPE_ACCOUNT_MAPPING = "Softmar Agresso Charge Type Account Mapping";
        public const string SOFTMAR_GRADE_ACCOUNT_MAPPING = "Softmar Agresso Grade Account Mapping";
        public const string SOFTMAR_BUNKER_PROCUREMENT_PO = "Softmar Bunker Procurement - PO";
        public const string SOFTMAR_BUNKER_INVENTORY = "Softmar Bunker Inventory";
        public const string SOFTMAR_BUNKER_GRN = "Softmar Bunker GRN";
        public const string SOFTMAR_RESPONSIBLE_USER_MAPPING = "Softmar Responsible User Mapping";
        public const string SOFTMAR_BUNKER_INVENTORY_MGR_MAPPING = "Softmar Bunker Inventory Manager Mapping";
        public const string SOFTMAR_COMMISSION_MANAGERS_MAPPING = "Softmar Commission Managers Legal Entity Mapping";
        public const string WINSDS_PURCHASE_ORDER_ERROR = "WinSDS Purchase Order Error List";
        public const string WINSDS_PURCHASE_ORDER_VIEW = "WinSDS Purchase Order View";
        public const string WINSDS = "WinSDS Menu";
        public const string WINSDS_PURCHASE_ORDER = "WinSDS Purchase Order Menu";
        public const string WINSDS_GRN = "WinSDS GRN Menu";
        public const string SOFTMAR_VOYAGE_MASTER = "Softmar Voyage Master";
        public const string DADESK_VESSEL = "DA Desk Vessel";
        public const string DADESK_AGENT = "DA Desk Agent";
        public const string DADESK_COMPANY = "DA Desk Company";
        public const string DADESK_BANK = "DA Desk Bank";
        public const string DADESK_ACCOUNT = "DA Desk Account";
        public const string DADESK_PORT = "DA Desk Port";
        public const string COMPASS_CREW_PAYROLL = "Compass Crew Payroll";
        public const string WINSDS_PURCHASE_ORDER_PRODUCT_ACC_MAPPING = "WinSDS Product Account Mapping";


        User m_current_user;
        MainForm m_mainForm;
        
        public UserControlFactory(User current_user, MainForm mainForm)
        {
            m_current_user = current_user;
            m_mainForm = mainForm;
        }

        public UserControl GetUserControl(string key)
        {
            UserControl uc = (UserControl)m_userControlCollection[key];
            if (uc == null)
            {
                switch (key)
                {
                    case ADMIN:
                        m_userControlCollection.Add(key, new UserControlHeader(ADMIN, m_current_user, m_mainForm, "treeNodeAdmin"));
                        break;
                    case USER:
                        m_userControlCollection.Add(key, new UserControlManageUser(USER, m_current_user, m_mainForm));
                        break;
                    case USER_ROLE:
                        m_userControlCollection.Add(key, new UserControlManageUserRole(USER_ROLE, m_current_user, m_mainForm));
                        break;
                    case CONFIGURATION:
                        m_userControlCollection.Add(key, new UserControlHeader(CONFIGURATION, m_current_user, m_mainForm, "treeNodeConfiguration"));
                        break;
                    case SCHEDULE_TASK:
                        m_userControlCollection.Add(key, new UserControlScheduleTask(SCHEDULE_TASK, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR:
                        m_userControlCollection.Add(key, new UserControlHeader(SOFTMAR, m_current_user, m_mainForm, "treeNodeSoftmar"));
                        break;
                    case SOFTMAR_TCRELET:
                        m_userControlCollection.Add(key, new UserControlSoftmarTCRelet(SOFTMAR_TCRELET, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_VESSEL:
                        m_userControlCollection.Add(key, new UserControlSoftmarVessel(SOFTMAR_VESSEL, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_VOYAGECARGORELET:
                        m_userControlCollection.Add(key, new UserControlSoftmarVoyageCargoRelat(SOFTMAR_VESSEL, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_FREIGHTHIREINVOICE :
                        m_userControlCollection.Add(key, new UserControlSoftmarFreightHireInvoice(SOFTMAR_FREIGHTHIREINVOICE, m_current_user, m_mainForm));
                        break;
                    case ADMIN_MAPPING_MASTER:
                        m_userControlCollection.Add(key, new UserControlHeader(ADMIN_MAPPING_MASTER, m_current_user, m_mainForm, "treeNodeMappingMaster"));
                        break;
                    case SOFTMAR_VESSEL_MAPPING:
                        m_userControlCollection.Add(key, new UserControlSoftmarVesselMapping(SOFTMAR_VESSEL_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_PROFITCENTRE_MAPPING:
                        m_userControlCollection.Add(key, new UserControlSoftmarProfitCentreMapping(SOFTMAR_PROFITCENTRE_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_SUPPLIER_CUSTOMER_MAPPING:
                        m_userControlCollection.Add(key, new UserControlSoftmarSupplierCustomerMapping(SOFTMAR_SUPPLIER_CUSTOMER_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_CHARGE_TYPE_ACCOUNT_MAPPING:
                        m_userControlCollection.Add(key, new UserControlSoftmarChargeTypeAccountMapping(SOFTMAR_CHARGE_TYPE_ACCOUNT_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_GRADE_ACCOUNT_MAPPING:
                        m_userControlCollection.Add(key, new UserControlSoftmarGradeAccountMapping(SOFTMAR_GRADE_ACCOUNT_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_BUNKER_PROCUREMENT_PO:
                        m_userControlCollection.Add(key, new UserControlSoftmarBunkerPO(SOFTMAR_BUNKER_PROCUREMENT_PO, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_BUNKER_INVENTORY:
                        m_userControlCollection.Add(key, new UserControlSoftmarBunkerInventory(SOFTMAR_BUNKER_INVENTORY, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_BUNKER_GRN:
                        m_userControlCollection.Add(key, new UserControlSoftmarBunkerGRN(SOFTMAR_BUNKER_GRN, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_COMMISSION_MANAGERS_MAPPING:
                        m_userControlCollection.Add(key, new UserControlCommissionManagersLegalEntityMapping(SOFTMAR_COMMISSION_MANAGERS_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_STATEMENT:
                        m_userControlCollection.Add(key, new UserControlSoftmarStatementInvoice(SOFTMAR_STATEMENT, m_current_user, m_mainForm));
                        break;
                    case WINSDS_PURCHASE_ORDER_ERROR:
                        m_userControlCollection.Add(key, new UserControlWinSDSPurchaseOrderError(WINSDS_PURCHASE_ORDER_ERROR, m_current_user, m_mainForm));
                        break;
                    case WINSDS_PURCHASE_ORDER_VIEW:
                        m_userControlCollection.Add(key, new UserControlWinSDSPurchaseOrderView(WINSDS_PURCHASE_ORDER_VIEW, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_VOYAGE_MASTER:
                        m_userControlCollection.Add(key, new UserControlSoftmarVoyageMasterAlert(SOFTMAR_VOYAGE_MASTER, m_current_user, m_mainForm));
                        break;
                    case WINSDS:
                        m_userControlCollection.Add(key, new UserControlHeader(WINSDS, m_current_user, m_mainForm, "treeNodeWinSDS"));
                        break;
                    case WINSDS_PURCHASE_ORDER:
                        m_userControlCollection.Add(key, new UserControlHeader(WINSDS_PURCHASE_ORDER, m_current_user, m_mainForm, "treeNodeWinSDSPO"));
                        break;
                    case WINSDS_GRN:
                        m_userControlCollection.Add(key, new UserControlHeader(WINSDS_GRN, m_current_user, m_mainForm, "treeNodeWinSDSGRN"));
                        break;
                    case DADESK_VESSEL:
                        m_userControlCollection.Add(key, new UserControlDaDeskVesselMapping(DADESK_VESSEL, m_current_user, m_mainForm));
                        break;
                    case DADESK_AGENT:
                        m_userControlCollection.Add(key, new UserControlDaDeskAgentMapping(DADESK_AGENT, m_current_user, m_mainForm));
                        break;
                    case DADESK_COMPANY:
                        m_userControlCollection.Add(key, new UserControlDaDeskCompanyMapping(DADESK_COMPANY, m_current_user, m_mainForm));
                        break;
                    case DADESK_BANK:
                        m_userControlCollection.Add(key, new UserControlDaDeskBankMapping(DADESK_BANK, m_current_user, m_mainForm));
                        break;
                    case DADESK_ACCOUNT:
                        m_userControlCollection.Add(key, new UserControlDaDeskAccountMapping(DADESK_ACCOUNT, m_current_user, m_mainForm));
                        break;
                    case DADESK_PORT:
                        m_userControlCollection.Add(key, new UserControlDaDeskPortMapping(DADESK_PORT, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_RESPONSIBLE_USER_MAPPING:
                        m_userControlCollection.Add(key, new UserControlSoftmarResponsibleUserMapping(SOFTMAR_RESPONSIBLE_USER_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_BUNKER_INVENTORY_MGR_MAPPING:
                        m_userControlCollection.Add(key, new UserControlSoftmarBunkerInventoryManagerMapping(SOFTMAR_BUNKER_INVENTORY_MGR_MAPPING, m_current_user, m_mainForm));
                        break;
                    case SOFTMAR_PROFORMA_INVOICE:
                        m_userControlCollection.Add(key, new UserControlSoftmarProforma(SOFTMAR_PROFORMA_INVOICE, m_current_user, m_mainForm));
                        break;
                    case COMPASS_CREW_PAYROLL:
                        m_userControlCollection.Add(key, new UserControlCompasCrewPayroll(COMPASS_CREW_PAYROLL, m_current_user, m_mainForm));
                        break;
                    case WINSDS_PURCHASE_ORDER_PRODUCT_ACC_MAPPING:
                        m_userControlCollection.Add(key, new UserControlWinSDSItemCodeAccountMapping(WINSDS_PURCHASE_ORDER_PRODUCT_ACC_MAPPING, m_current_user, m_mainForm));
                        break;
                }
            }
            uc = (UserControl)m_userControlCollection[key];
            return uc;
        }
        public static IList GetFormNames()
        {
            IList m_formNames;
            m_formNames = new ArrayList();
            m_formNames.Add(USER);
            m_formNames.Add(USER_ROLE);
            m_formNames.Add(SOFTMAR);
            return m_formNames;
        }

        public void ClearUserControls()
        {
            m_userControlCollection.Clear();
        }
    }
}